package cn.wolfcode.luowowo.mgrsite.controller;

import cn.wolfcode.luowowo.article.domain.Destination;
import cn.wolfcode.luowowo.article.service.IDestinationService;
import cn.wolfcode.luowowo.common.query.DestinationQueryObject;
import cn.wolfcode.luowowo.common.util.AjaxResult;
import com.github.pagehelper.PageInfo;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/destination")
public class DestinationController {

    @Reference
    private IDestinationService destinationService;

    @RequestMapping("list")
    public String list(@ModelAttribute("qo") DestinationQueryObject qo, Model model){
        PageInfo pageInfo = destinationService.query(qo);
        model.addAttribute("pageInfo",pageInfo);


          List<Destination>list= destinationService.getToasts(qo.getParentId());
          model.addAttribute("toasts",list);


        return "destination/list";
    }

    @RequestMapping("/changeHotState")
    @ResponseBody
    public Object changeHotState(Long id,Integer hot){
        AjaxResult json = new AjaxResult();
        		try {
                   destinationService.changeHotState(id,hot);
        		} catch (Exception e) {
        			e.printStackTrace();
        			json.mark(e.getMessage());
        		}
        		return json;
    }
}
